package com.timoon.webcomponent.utility.titlelist.dangdang.panel;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.timoon.sample.dao.PassageDAO;
import com.timoon.sample.dao.model.Passage;
import com.timoon.sample.dao.model.PassageExample;
import com.timoon.webcomponent.utility.titlelist.dangdang.DangdangTitleListParameter;
import com.timoon.webcomponent.utils.WebConstantor;

/**
 *<p>循环文章标题</p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class ListPanel extends Panel {
	
	@SpringBean
	private PassageDAO passageDAOImpl;

	private DangdangTitleListParameter parameter;
	
	private Integer count=1;
	
	private Integer type;
	
	public ListPanel(String id,DangdangTitleListParameter parameter,Integer type) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.parameter=parameter;
		this.type=type;
		
		this.doPanel();
	}
	private void doPanel(){
		
		@SuppressWarnings("unchecked")
		List<Passage> passages=this.passageDAOImpl.selectByExampleWithBLOBs(new PassageExample(){{
			this.createCriteria().andTypeEqualTo(type).andStatusNotEqualTo(0).andPublicedEqualTo(WebConstantor.PUBLIC_ON);
		}});
		ListView<Passage> listView=new ListView<Passage>("wk_list",passages) {

			@Override
			protected void populateItem(ListItem<Passage> arg0) {
				// TODO Auto-generated method stub
				final Passage passage=arg0.getModelObject();
				@SuppressWarnings({ "rawtypes", "unchecked" })
				BookmarkablePageLink link=new BookmarkablePageLink("wk_link", parameter.getTargetPage(),new PageParameters(){{
					this.set("passage_id", passage.getId());
				}});
				arg0.add(link);
				
				link.add(new Label("wk_count",count));
				link.add(new Label("wk_title",passage.getTitle()));
				
				count++;
			}
		};
		add(listView);
	}
	public PassageDAO getPassageDAOImpl() {
		return passageDAOImpl;
	}
	public void setPassageDAOImpl(PassageDAO passageDAOImpl) {
		this.passageDAOImpl = passageDAOImpl;
	}

}
